package com.tmc.service.intair;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tmc.bean.common.ContextInfo;
import com.tmc.dao.impl.TripartitePolicyDaoImpl;
import com.tmc.entity.intair.IntairOrder;
import com.tmc.entity.intair.TripartitePolicy;

@Service
@Transactional
public class TripartitePolicyOrderServiceImpl {
	
	private  Log logger = LogFactory.getLog(this.getClass());
	
	@Autowired
	private TripartitePolicyServiceImpl  TripartiteService;
	
	@Autowired
	private TripartitePolicyDaoImpl  TripartiteDao;
	
	@Autowired 
	private IntairOrderServiceImpl orderServiceImpl;
	
	public synchronized void run() {
		logger.error("执行一次订单更新！");
		// 查询昨天所有的订单(包括创建和更新)
		
		List<IntairOrder> dbOrders = null;
		try {
			dbOrders = orderServiceImpl.findByYesterday(new ContextInfo());
		} catch (Exception e) {
			System.out.println("查询订单出错！");
		}
		System.out.println("查询订单完毕！");
		// 查询昨天所有已发布的三方政策
		List<TripartitePolicy> dbPolicys = TripartiteDao.findListByPolicy(new ContextInfo(), new TripartitePolicy());
		
		TripartiteService.matchPolicy(dbOrders, dbPolicys);
		
	}
	
	
	
}
